package com.sheep.jucdemo.part2.part2_10;

/**
 * @Date 2022/4/13 22:20
 * @Created by sheep
 */
public class Test2_10_1 {

    private static int num = 0;
    private static boolean ready = false;

    public static class ReadThread extends Thread{
        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()){
                if (ready){//(1)
                    System.out.println(num + num);//(2)
                }

            }
        }
    }

    public static class WriteThread extends Thread{
        @Override
        public void run() {
            num = 2;//(3)
            ready = true;//(4)
            System.out.println("writeThread set over...");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ReadThread rt = new ReadThread();
        rt.start();

        WriteThread wt = new WriteThread();
        wt.start();

        Thread.sleep(10);
        rt.interrupt();
        System.out.println("manin exit");
    }
}
